﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using System.ComponentModel.DataAnnotations.Schema;



namespace WebApplication2
{
    public partial class login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
           
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            string id = TextBox1.Text;
            string password = TextBox2.Text;
            if (id == "" || password == "")
            {
                Label1.Text = "请输入账号密码";
            }


            string sql=null;
            if(DropDownList1.SelectedValue.ToString()=="3")//学生登入
            {
                sql = "select * from xs where zh='" + id + "' and mm='" + password + "'";
            }
            else if(DropDownList1.SelectedValue.ToString() == "2")//老师登入
            {
                sql = "select * from ls where zh='" + id + "' and mm='" + password + "'";
            }
            Database db = new Database();
            
            DataTable ds = db.SelectSQL(sql);
            if (ds.Rows.Count > 0)
            {
                if (DropDownList1.SelectedValue.ToString() == "3")
                {
                    Session["xh"] = ds.Rows[0]["xh"].ToString();
                    Response.Redirect("student//主页.aspx");
                }
                else if (DropDownList1.SelectedValue.ToString() == "2")
                {
                    Session["id_ls"] = ds.Rows[0]["id"].ToString();//绑定老师的id
                    Response.Redirect("teacher//主页.aspx");
                }
                Label1.Text = "登入成功";
            }
            else
            {
                TextBox1.Text = "账号或密码错误！";
            }
        }
    }
}